<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>车队管理</title>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/js/jquery-easyui-1.4.1/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/js/jquery-easyui-1.4.1/themes/icon.css"/>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/js/jquery-easyui-1.4.1/jquery.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/js/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/js/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
    <script type="text/javascript">
        /* 添加操作列 */
       /* function formatOper(val, row, index) {
            var a = '<a href="javascript:void(0);" value="' + row.teamId + '" onclick="Administration(' + index + ',' + row.teamId + ')"> 管理 </a>';
            return a;
        }

        /!* 管理 *!/
        function Administration(index, teamId) {

            $("#teamList").datagrid("selectRow", index);
            var data = $("#teamList").datagrid("getSelected");
            $("#Administration").window({
                onLoad: function () {
                    $("#input").val(teamId);
                    $("#teamList2").datagrid("load", {
                        "teamId": data.teamId
                    });
                    $("#teamList1").datagrid("load", {
                        "teamId": data.teamId
                    });
                }

            }).window('open').dialog('setTitle', '管理' + teamId + '车队');
        }*/

        /* 获取选中项的id */
        function getSelectionsIds() {
            var teamList = $("#teamList");
            var sels = teamList.datagrid("getSelections");
            var ids = [];
            for (var i in sels) {
                ids.push(sels[i].teamId);
            }
            ids = ids.join(",");
            return ids;
        }

        //将时间戳转换为正常的时间格式

        function timestampToTime(timestamp) {
            var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
            var Y = date.getFullYear() + '-';
            var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            var D = date.getDate() + ' ';
            var h = date.getHours() + ':';
            var m = date.getMinutes() + ':';
            var s = date.getSeconds();
            return Y + M + D;
        };
        var toolbar = [{
            text: '车队名称：<input id = "serach1" class="search" style="width:60px;"/>',
        }, {
            text: '搜索',
            iconCls: 'icon-search',
            handler: function () {
                var teamName = $("#serach1").val();
                $("#teamList").datagrid("load", {
                    teamName: teamName,
                })
            }
        }, {
            text: '重置',
            iconCls: 'icon-mini-refresh',
            handler: function () {
                $("#serach1").val("");
            }
        }, {
            text: '新增',
            iconCls: 'icon-add',
            handler: function () {
                $('#teamAdd').window('open');
            }
        }, {
            text: '编辑',
            iconCls: 'icon-edit',
            handler: function () {
                var ids = getSelectionsIds();
                if (ids.length == 0) {
                    $.messager.alert('提示', '必须选择一个车队才能编辑!');
                    return;
                }
                if (ids.indexOf(',') > 0) {
                    $.messager.alert('提示', '只能选择一个车队!');
                    return;
                }
                $.messager.confirm('确认', '确定要修改ID为' + ids + '的用户吗？', function (r) {
                    if (r) {
                        $('#teamUpdate').window({
                            onLoad: function () {
                                /* 由于获取到的user是一个数组，这里必须加上【0】 */
                                var team = $("#teamList").datagrid("getSelections")[0];
                                $("#teamUpdate").form("load", {
                                    teamId: team.teamId,
                                    teamName: team.teamName,
                                    admin: team.admin,
                                    phone: team.phone
                                });
                            }
                        }).window('open');
                    }
                });
            }
        }, {
            text: '批量删除',
            iconCls: 'icon-cancel',
            handler: function () {
                var ids = getSelectionsIds();
                if (ids.length < 1) {
                    $.messager.alert('提示', '必须选择车队才能删除!');
                    return;
                }
                $.messager.confirm('确认', '确定删除ID为 ' + ids + ' 的车队吗？', function (r) {
                    if (r) {
                        $.post("${pageContext.request.contextPath}/busTeam/delete", {'ids': ids}, function (data) {
                            // $.messager.alert('data',data.code);
                            if (data.code == 200) {
                                $.messager.alert('提示', '删除车队成功!', undefined, function () {
                                    $("#teamList").datagrid('reload');
                                });
                            } else {
                                $.messager.alert('提示', '删除车队失败!可能该车队下有车辆！', undefined, function () {
                                    $("#teamList").datagrid('reload');
                                });
                            }
                        }, "json");
                    }
                });
            }
        }, {
            text: '导入',
            iconCls: 'icon-remove',
            handler: function () {
                $('#upload').window('open');
            }
        }, {
            text: '导出',
            iconCls: 'icon-remove',
            handler: function () {
                $.messager.alert("提示", "敬请期待");
                // var optins = $("#teamList").datagrid("getPager").data("pagination").options;
                // $("<form>").attr({
                // 	"action":"/busTeam/chu/excel",
                // 	"method":"POST"
                // }).appendTo("body").submit();
            }
        }];
    </script>

</head>
<body>
<div>
    <table class="easyui-datagrid" id="teamList" title="车队管理"
           data-options="singleSelect:false,collapsible:true,pagination:true,url:'${pageContext.request.contextPath}/busTeam/search',method:'post',pageSize:5,toolbar:toolbar,pageList:[2,5,10],striped:true,rownumbers:true">
        <thead>
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
            <th data-options="field:'teamId',width:60,hidden:true">ID</th>
            <%--            <th data-options="field:'_operate',width:100,align:'center',formatter:formatOper">操作</th>--%>
            <th data-options="field:'teamName',width:100">车队名称</th>
            <th data-options="field:'admin',width:100">负责人</th>
            <th data-options="field:'adminPhone',width:100">负责人电话</th>
            <th data-options="field:'createdTime',width:100">添加时间</th>
        </tr>
        </thead>
    </table>
</div>
<div id="teamAdd" class="easyui-window" title="新增车队"
     data-options="modal:true,closed:true,iconCls:'icon-save',href:'${pageContext.request.contextPath}/to/team_add'"
     style="width:700px;height:260px;padding:10px;top: 80px">
    The window content.
</div>
<div id="teamUpdate" class="easyui-window" title="修改车队"
     data-options="model:true,closed:true,iconCls:'icon-update',href:'${pageContext.request.contextPath }/to/team_update'"
     style="width:700px;height:300px;padding:10px;top: 80px">
    The window context.
</div>
<div id="Administration" class="easyui-window"
     data-options="collapsible:false,maximizable:false,minimizable:false,model:true,closed:true,iconCls:'icon-update',href:'${pageContext.request.contextPath }/to/Administration'"
     style="width:900px;height:400px;padding:10px;top: 30px">
</div>
<div id="upload" class="easyui-dialog" title="上传车队信息" style="width:400px;height:200px;"
     data-options="closed:true,iconCls:'icon-save',resizable:true,modal:true,href:'${pageContext.request.contextPath }/to/upload'">
    Dialog Content.
</div>
</div>
</body>
</html>